import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { ConfigService } from '@nestjs/config'
import { ResponseInterceptor } from './interceptors/response.interceptor'
import { ValidationPipe } from '@nestjs/common'

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  // 获取 ConfigService 实例
  const configService = app.get(ConfigService)
  app.enableCors()
  app.useGlobalPipes(new ValidationPipe({}))
  app.useGlobalInterceptors(new ResponseInterceptor())

  // 从 ConfigService 中获取端口配置
  const port = configService.get<number>('port')
  await app.listen(port ?? 7001)
}

bootstrap()
